﻿/**********************************************************************
 * @file   FITKCGNSData.h
 * @brief  CGNS 数据
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2024-09-24
 *********************************************************************/

#ifndef _FITKFCGNSDATA_H__
#define _FITKFCGNSDATA_H__

#include "FITKCGNSIOAPI.h"
#include <QVector>
#include <QMap>
#include <QHash>

namespace IO
{
    /**
     * @brief  点数据信息结构体
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-19
     */
    struct VertexDataInfo
    {
        double x = 0;
        double y = 0;
        double z = 0;
    };
    /**
     * @brief  单元数据信息结构体
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-20
     */
    struct CellDataInfo
    {
        int cId = 0;
        int type = 0;//Interface::FITKModelEnum::FITKEleType
        QList<int> Points;
    };
    /**
     * @brief  section数据
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-21
     */
    struct SectionDataStruct
    {
        QString name;
        QVector<int> ids;
    };

    struct BCDataStruct
    {
        QString name;
        int bcType = 0;
        int structType = 0;
        int dataType = 0;//1 点 2 单元
        QVector<int> ids;
        int range[2][3] = { 0 };
    };

    struct FamiltyDataStruct
    {
        QString name;
        QVector<QPair<QString, int>> familtyType;
    };

    struct ZoneDataStruct
    {
        int zoneType = 0;//CGNS_ENUMT(ZoneType_t)
        QVector<VertexDataInfo> m_verlist{};
        QVector<CellDataInfo> m_cellList{};
        QVector<SectionDataStruct> m_sections{};
        QVector<BCDataStruct> m_bcs{};
        QMap<QString, QVector<double>> m_pointScalars;
        QMap<QString, QVector<double>> m_cellScalars;
    };
   
    /**
     * @brief  存储基础信息
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-20
     */
    class FITKCGNSIOAPI BaseDataStruct
    {
    public:

        /**
         * @brief  构造函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-07-29
         */
        BaseDataStruct() = default;
        /**
         * @brief  析构函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-07-29
         */
        ~BaseDataStruct();

        void setBaseInfo(QString name, int cDim, int pDim);

        int getZoneCount();
        ZoneDataStruct* getZoneData(int index);
        void setZoneSize(int size);
        FamiltyDataStruct* getFamiltyData(int index);
        void setFamiltySize(int size);

        bool isAllZoneType(int zoneType);

    private:
        QString m_baseName{};
        int m_cell_dim{ -1 };
        int m_phys_dim{ -1 };
        QVector<ZoneDataStruct> m_zoneDatas{};
        QVector<FamiltyDataStruct> m_familty{};
    };

    /**
     * @brief  CGNS数据存储
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-09-19
     */
    class FITKCGNSIOAPI FITKCGNSData
    {
    public:
        enum FileTypeEnum
        {
            None_Type = 0,
            ADF_Type = 1,
            HDF5_Type = 2,
            ADF2_Type = 3,
        };

        /**
         * @brief  构造函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-07-29
         */
        FITKCGNSData() = default;
        /**
         * @brief  析构函数
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-07-29
         */
        ~FITKCGNSData();

        int getBaseCount();
        BaseDataStruct* getBaseData(int index);
        void setBaseSize(int size);

        void setFileType(FileTypeEnum type);
        void setFileVersion(float version);
        void setFilePrecision(int precision);

    private:
        FileTypeEnum m_file_type{ FileTypeEnum::None_Type };
        float m_fileVersion{ -1 };
        int m_filePrecision{ -1 };

        QVector<BaseDataStruct> m_baseDatas{};

    };

}

#endif